package com.company.cloud.gateway.component.filter.pre;

import org.slf4j.MDC;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.exception.ZuulException;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.log4j.Log4j2;

/**
 * 生成日志链路追踪id，并传入header中
 * */
@Log4j2
@Component
public class TraceFilter extends ZuulFilter{

	@Override
	public String filterType() {
		return FilterConstants.PRE_TYPE;
	}

	@Override
	public int filterOrder() {
		return FilterConstants.FORM_BODY_WRAPPER_FILTER_ORDER-1;
	}
	
	@Override
	public boolean shouldFilter() {
		return true;
	}

	@Override
	public Object run() throws ZuulException {
//		String traceId=IdUtil.fastSimpleUUID();
//		MDC.put(key, val);
//		System.out.println(StrUtil.format("", "-1"));
		log.info("+++++ZuulFilter -> TraceFilter -> filterOrder={}", this.filterOrder());
		return null;
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	


}
